사이트 내 전체검색
PHP
curl로 post형식 데이터를 넘길 때 문자열/배열
로빈아빠
https://cmd.kr/php/873 URL이 복사되었습니다.

본문

curl을 사용해서 post값을 넘겨주려고 하는데, 포스트하는 데이터를 배열로 넘기면 서버에서 인식을 안하고 문자열로 넘기면 작동을 합니다.... 

 

두 방법을 사용할 때 패킷에 무슨 차이가 있는지요? 

 

아래에 코드를 첨부합니다. 

 

 

=========================================== 

 

//$post_data = array("p_userid"=>"아이디", "p_passwd"=>"비번"); // 이 코드를 넣으면 서버에서 인식하지 않음. 

$post_data = "p_userid=아이디&p_passwd=비번"; // 이 코드를 넣으면 작동함 

 

$ch = curl_init(); 

$ckfile=tempnam(".", "CURLCOOKE"); 

 

 

 

curl_setopt($ch, CURLOPT_URL, 'http://somedomain/login.jsp'); 

 

curl_setopt($ch, CURLOPT_POST, true); 

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

curl_setopt ($ch, CURLOPT_HEADER, 1); 

curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); 

$content = curl_exec($ch);

전체댓글수 2

 기술레벨커뮤니티레벨BiHon 11-08-25 05:19 소스보기

http://php.net/manual/en/function.curl-setopt.php 

CURLOPT_POSTFIELDS : The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, files thats passed to this option with the @ prefix must be in array form to work. 

 

If value is an array … multipart/form-data … 영어 해석은 스스로 하시길 바라며 이만 생략합니다. 

댓글목록

등록된 댓글이 없습니다.

PHP
871 (2/18P)

Search

Copyright © Cmd 명령어 18.119.132.223